
/**
 * @properties={typeid:24,uuid:"09099DCB-63DD-4FCB-83A2-F458EA0F1ADA"}
 */
function guardar() {
	if (codigo == null || descripcion == null || moneda_id == null || desayuno == null)
	{
		globals.DIALOGS.showWarningDialog('Aviso','Por favor, ingrese todos los campos obligatorios','OK')
		return false
	}
	if (valida() == false)
	{
		globals.DIALOGS.showErrorDialog('Aviso','El código ya existe. Por favor, ingrese otro','OK')
		return false
	}
	if (databaseManager.saveData() == true)
	{
		globals.DIALOGS.showInfoDialog('Aviso','Datos modificados con éxito','OK')
		return true
	}
	else
	{
		globals.DIALOGS.showWarningDialog('Aviso','Ocurrio un error al grabar. Inténtelo nuevamente', 'OK')
		return false
	}
}

/**
 * @properties={typeid:24,uuid:"12B251CC-BE41-4499-8493-A61AF2649D61"}
 */
function valida()
{
	var $sql = 'SELECT tarifa_id FROM tarifas WHERE upper(codigo) = upper(?) AND hotel_id = ? AND tarifa_id = ?'
	var $args = [codigo, globals.gHotelId, tarifa_id]
	var $ds = databaseManager.getDataSetByQuery('hoteleria',$sql,$args,-1)
	if ($ds.getMaxRowIndex() == 0)
		return true
	return false
}

/**
 * @properties={typeid:24,uuid:"83DD8E65-A97F-4F91-B3F9-F2E5076711FD"}
 */
function cancelar() {
	databaseManager.revertEditedRecords()
}

/**
 * Callback method for when form is shown.
 *
 * @param {Boolean} firstShow form is shown first time after load
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"B7C16884-E8A8-4D30-B0F2-7076B1FEB30B"}
 */
function onShow(firstShow, event) {
	databaseManager.setAutoSave(false)
}

/**
 * Handle hide window.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"B81E6EDF-AF8F-436C-8826-E93AA44B5645"}
 */
function onHide(event) {
	databaseManager.revertEditedRecords()
	return true
}
